package junior.db.mapping;

import junior.util.value.ValueUtils;

import java.util.HashMap;
import java.util.Map;

public class MappingProvider {
	private static final Map<String, MappingProvider> namespaceMap = new HashMap<String, MappingProvider>();

	public static TableMapping getTableMapping(String namespace) {
		namespace = ValueUtils.ifNull(namespace, "");
		return namespaceMap.get(namespace).getTableMapping();
	}
	public static ColumnMapping getColumnMapping(String namespace) {
		namespace = ValueUtils.ifNull(namespace, "");
		return namespaceMap.get(namespace).getColumnMapping();
	}
	
	public MappingProvider() {
		this(true);
	}
	
	public MappingProvider(boolean addToNamespace) {
		if (addToNamespace) {
			init("");
		}
	}
	
	public MappingProvider(String namespace) {
		init(namespace);
	}

	private TableMapping tableMapping;
	private ColumnMapping columnMapping;
	
	private void init(String namespace) {
		namespaceMap.put(namespace, this);
	}
    
    public ColumnMapping getColumnMapping() {
        return columnMapping;
    }
    
    public void setColumnMapping(ColumnMapping columnMapping) {
        this.columnMapping = columnMapping;
    }
    
    public TableMapping getTableMapping() {
        return tableMapping;
    }
    
    public void setTableMapping(TableMapping tableMapping) {
        this.tableMapping = tableMapping;
    }
}
